define(['zepto', 'utils', 'JST', 'sui', 'submitForm'], function($, utils, JST){
  return {
    init: function(data) {
      this.courseRoundId = data.courseRoundId;
      
      this.initPicker();
      this.initSubmit();
     console.log(data)
    },
    
    
    initPicker: function() {
      var that = this;
      
      $('input[data-name="staticSquat"]').picker({
        toolbarTemplate: '<header class="bar bar-nav">\
          <button class="button button-link pull-left cancel-picker">取消</button>\
          <h1 class="title">请选择静蹲时间</h1>\
          <button class="button button-link pull-right close-picker">确定</button>\
          </header>',
          cssClass: 'evaluation-picker',
          onOpen: function(picker) {
            that.currentPicker = $(this.input)
          },
          cols: [
            {
              textAlign: 'center',
              values: ['LEVELONE', 'LEVELTWO', 'LEVELTHREE', 'LEVELFOUR'],
              displayValues: ['<30s', '30-60s', '61-90s', '>90s']
            }
          ],
          formatValue: function (picker, value, displayValue){
            $(this.input).parent().find('input[type="hidden"]').val(value)
            return displayValue
          },
        });
      
      $('input[data-name="pushUp"]').picker({
        toolbarTemplate: '<header class="bar bar-nav">\
          <button class="button button-link pull-left cancel-picker">取消</button>\
          <h1 class="title">俯卧撑（30s）可以做的个数</h1>\
          <button class="button button-link pull-right close-picker">确定</button>\
          </header>',
          cssClass: 'evaluation-picker',
          onOpen: function(picker) {
            that.currentPicker = $(this.input)
          },
          cols: [
            {
              textAlign: 'center',
              values: ['LEVELONE', 'LEVELTWO', 'LEVELTHREE', 'LEVELFOUR'],
              displayValues: ['<10', '10-20', '20-30', '>30']
            }
          ],
          formatValue: function (picker, value, displayValue){
            $(this.input).parent().find('input[type="hidden"]').val(value)
            return displayValue
          },
        });
      
      $('input[data-name="vUp"]').picker({
        toolbarTemplate: '<header class="bar bar-nav">\
          <button class="button button-link pull-left cancel-picker">取消</button>\
          <h1 class="title">两头起（30s）能做多少个</h1>\
          <button class="button button-link pull-right close-picker">确定</button>\
          </header>',
          cssClass: 'evaluation-picker',
          onOpen: function(picker) {
            that.currentPicker = $(this.input)
          },
          cols: [
            {
              textAlign: 'center',
              values: ['LEVELONE', 'LEVELTWO', 'LEVELTHREE', 'LEVELFOUR'],
              displayValues: ['<10', '10-15', '16-20', '>20']
            }
          ],
          formatValue: function (picker, value, displayValue){
            $(this.input).parent().find('input[type="hidden"]').val(value)
            return displayValue
          },
        });
      
      $('input[data-name="standardBobi"]').picker({
        toolbarTemplate: '<header class="bar bar-nav">\
          <button class="button button-link pull-left cancel-picker">取消</button>\
          <h1 class="title">一分钟波比跳</h1>\
          <button class="button button-link pull-right close-picker">确定</button>\
          </header>',
          cssClass: 'evaluation-picker',
          onOpen: function(picker) {
            that.currentPicker = $(this.input)
          },
          cols: [
            {
              textAlign: 'center',
              values: ['true', 'false'],
              displayValues: ['标准', '简化']
            }
          ],
          formatValue: function (picker, value, displayValue){
            $(this.input).parent().find('input[type="hidden"]').val(value)
            return displayValue
          },
        });
      
        $(document).on("click", ".cancel-picker", function() {
        
          $.closeModal(".picker-modal.modal-in")
          var currentElement = $(that.currentPicker)
          console.log(currentElement.data("val"))
          var val = currentElement.data("val") ? currentElement.data("val") : ""
          var defaultVal = currentElement.data("default-val") ? currentElement.data("default-val") : ""
          
          currentElement.parent().find('input[type="hidden"]').val(val)
          currentElement.val(defaultVal)
        })
      
      
    },
    
    initSubmit: function() {
      var that = this;
      $(document).on("click", ".save-button", function() {
        $(".submit-btn").trigger("click");
      })
      
      $("form").submitform({
          successUrl: $(".fs-header-small a").attr("href")
      });
    }
  }
})